package main



import (
"fmt"
"net"
)

func main() {
// 创建监听
	socket, err := net.ListenUDP("udp4", &net.UDPAddr{
		IP:   net.IPv4(192,168,1,5),
		Port: 10086,
	})
	if err != nil {
		fmt.Println("监听失败!", err)
		return
	}
	defer socket.Close()
	fmt.Println("server start!")
	for {
		// 读取数据
		data := make([]byte, 4096)
		_, remoteAddr, err := socket.ReadFromUDP(data)
		if err != nil {
			fmt.Println("读取数据失败!", err)
			continue
		}
		fmt.Println("from ", remoteAddr)
		fmt.Printf("%s\n\n", data)


	}
}
